<!DOCTYPE html>



  


<html class="theme-next muse use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
















  
  
  <link href="/blog/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/blog/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/blog/css/main.css?v=5.1.4" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/blog/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/blog/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/blog/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/blog/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="Hexo, NexT" />










<meta property="og:type" content="website">
<meta property="og:title" content="smallmuou&#39;s blog">
<meta property="og:url" content="http://smallmuou.gitee.io/blog/page/6/index.html">
<meta property="og:site_name" content="smallmuou&#39;s blog">
<meta property="og:locale" content="zh-Hans">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="smallmuou&#39;s blog">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/blog/',
    scheme: 'Muse',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://smallmuou.gitee.io/blog/page/6/"/>





  <title>smallmuou's blog</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left 
  page-home">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/blog/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">smallmuou's blog</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"><a href="https://github.com/smallmuou">https://github.com/smallmuou</a></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/blog/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/blog/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/blog/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/blog/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            
            关于
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            
  <section id="posts" class="posts-expand">
    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://smallmuou.gitee.io/blog/blog/2017/09/20/2017-09-20-外部可以访问而内部访问不了/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="smallmuou">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/blog/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="smallmuou's blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/blog/2017/09/20/2017-09-20-外部可以访问而内部访问不了/" itemprop="url">外部可以访问而内部访问不了</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-09-20T00:00:00+08:00">
                2017-09-20
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/blog/categories/运维/" itemprop="url" rel="index">
                    <span itemprop="name">运维</span>
                  </a>
                </span>

                
                
              
            </span>
          

          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>今天发现个非常有趣的问题，即netstat并没有发现80端口，但外部却可以正常访问，而更奇怪的是使用127.0.0.1或localhost访问时提示’Connection refused’.</p>
<p>一般情况是本地可以访问，但外部是无法访问，这个一般是由于服务只开启了本地监听。比如下面这个服务：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">tcp        0      0 127.0.0.1:18089             0.0.0.0:*                   LISTEN      28729/ssh</span><br></pre></td></tr></table></figure>
<p>然而在本例中，却是相反，想到了iptables端口转发，大家可以去看下我的另一篇文章 <a href="/网络/2017/08/18/iptables简述.html">《iptables简述》</a></p>
<p><img src="/images/iptables.jpg" alt="iptables"></p>
<p>端口转发是在NAT-PREROUTING进行的，从上图可以看出，内部访问是不走NAT-PREROUTING，这就解释了为何内部访问不了，那我们实际来看下iptables规则</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">volumio@volumio:~$ sudo iptables -t nat --list</span><br><span class="line">Chain PREROUTING (policy ACCEPT)</span><br><span class="line">target     prot opt <span class="built_in">source</span>               destination</span><br><span class="line">REDIRECT   tcp  --  anywhere             anywhere             tcp dpt:http redir ports 3000</span><br><span class="line"></span><br><span class="line">Chain INPUT (policy ACCEPT)</span><br><span class="line">target     prot opt <span class="built_in">source</span>               destination</span><br><span class="line"></span><br><span class="line">Chain OUTPUT (policy ACCEPT)</span><br><span class="line">target     prot opt <span class="built_in">source</span>               destination</span><br><span class="line"></span><br><span class="line">Chain POSTROUTING (policy ACCEPT)</span><br><span class="line">target     prot opt <span class="built_in">source</span>               destination</span><br></pre></td></tr></table></figure>
<p>从上面可以看到PREROUTING链有一个规则，即转发http端口至3000端口</p>
<p>那iptables如何配置端口转发？</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">volumio@volumio:/volumio$ sudo iptables -t nat -A PREROUTING -p tcp --dport 10022 -j REDIRECT --to-port 22</span><br><span class="line">volumio@volumio:~$ sudo iptables -t nat --list</span><br><span class="line">Chain PREROUTING (policy ACCEPT)</span><br><span class="line">target     prot opt <span class="built_in">source</span>               destination</span><br><span class="line">REDIRECT   tcp  --  anywhere             anywhere             tcp dpt:http redir ports 3000</span><br><span class="line">REDIRECT   tcp  --  anywhere             anywhere             tcp dpt:10022 redir ports 22</span><br><span class="line"></span><br><span class="line">Chain INPUT (policy ACCEPT)</span><br><span class="line">target     prot opt <span class="built_in">source</span>               destination</span><br><span class="line"></span><br><span class="line">Chain OUTPUT (policy ACCEPT)</span><br><span class="line">target     prot opt <span class="built_in">source</span>               destination</span><br><span class="line"></span><br><span class="line">Chain POSTROUTING (policy ACCEPT)</span><br><span class="line">target     prot opt <span class="built_in">source</span>               destination</span><br></pre></td></tr></table></figure>
<p>以上内容很清楚的解释了”外部可以访问而内部访问不了”，其实用的就是iptables的端口转发功能。</p>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://smallmuou.gitee.io/blog/blog/2017/09/20/2017-09-20-树莓派下编译及使用linphone客户端/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="smallmuou">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/blog/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="smallmuou's blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/blog/2017/09/20/2017-09-20-树莓派下编译及使用linphone客户端/" itemprop="url">树莓派下编译及使用linphone客户端</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-09-20T00:00:00+08:00">
                2017-09-20
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/blog/categories/树莓派/" itemprop="url" rel="index">
                    <span itemprop="name">树莓派</span>
                  </a>
                </span>

                
                
              
            </span>
          

          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>linphone是一款开源的SIP客户端工具，支持Linux、MacOS、Windows、iOS、Android以及树莓派，非常强大，本文将为大家展现如何在树莓派下编译及使用linphone客户端</p>
<h3 id="编译并安装"><a href="#编译并安装" class="headerlink" title="编译并安装"></a>编译并安装</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line">sudo apt-get install gcc</span><br><span class="line">sudo apt-get install openjdk-8-jre</span><br><span class="line">sudo apt-get install doxygen</span><br><span class="line">sudo apt-get install cmake graphviz</span><br><span class="line">sudo apt-get install python-setuptools</span><br><span class="line">sudo apt-get install python-pip</span><br><span class="line">sudo pip install pystache</span><br><span class="line">sudo apt-get install intltool</span><br><span class="line">sudo apt-get install nasm</span><br><span class="line">sudo apt-get install automake</span><br><span class="line">sudo apt-get install libtool</span><br><span class="line">sudo apt-get install gettext</span><br><span class="line">sudo apt-get install libx11-dev</span><br><span class="line"></span><br><span class="line">tar xzvf linphone-desktop.tar.gz</span><br><span class="line"><span class="built_in">cd</span> linphone-desktop</span><br><span class="line">./prepare.py -DENABLE_VPX=OFF -DENABLE_WEBRTC_AEC=OFF -DENABLE_OPENH264=ON -DENABLE_NON_FREE_CODECS=ON  no-ui</span><br><span class="line">make</span><br><span class="line"></span><br><span class="line"><span class="comment"># 成功后，执行如下命令即可完成安装</span></span><br><span class="line">sudo cp -rf OUTPUT/no-ui/* /</span><br></pre></td></tr></table></figure>
<h3 id="使用"><a href="#使用" class="headerlink" title="使用"></a>使用</h3><p>linphone提供了命令行工具linphonec，通知此命令，可以完成账号注册、呼叫、接听、声卡选择等操作.</p>
<ul>
<li>启动</li>
</ul>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 只支持音频</span></span><br><span class="line">linphonec</span><br><span class="line"></span><br><span class="line"><span class="comment"># 若需要开启视频</span></span><br><span class="line">linphonec -C</span><br><span class="line"></span><br><span class="line"><span class="comment"># 开启自动接听</span></span><br><span class="line">linphonec -a -C</span><br></pre></td></tr></table></figure>
<ul>
<li>账号注册</li>
</ul>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 查看当前账号</span></span><br><span class="line">proxy list</span><br><span class="line"></span><br><span class="line"><span class="comment"># 添加账号</span></span><br><span class="line">proxy add</span><br></pre></td></tr></table></figure>
<ul>
<li>接听</li>
</ul>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">answer</span><br></pre></td></tr></table></figure>
<ul>
<li>呼叫</li>
</ul>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">call 101</span><br></pre></td></tr></table></figure>
<ul>
<li>挂掉</li>
</ul>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">terminate</span><br></pre></td></tr></table></figure>
<ul>
<li>声卡</li>
</ul>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 所有声卡</span></span><br><span class="line">soundcard list</span><br><span class="line"></span><br><span class="line"><span class="comment"># 当前使用</span></span><br><span class="line">soundcard show</span><br><span class="line"></span><br><span class="line"><span class="comment"># 设置声卡</span></span><br><span class="line">soundcard use xx</span><br><span class="line"></span><br><span class="line"><span class="comment">#设置响铃声卡</span></span><br><span class="line">soundcard ring xx</span><br><span class="line"></span><br><span class="line"><span class="comment"># 设置播放声卡</span></span><br><span class="line">soundcard playback xx</span><br><span class="line"></span><br><span class="line"><span class="comment"># 设置录音声卡</span></span><br><span class="line">soundcard capture xx</span><br></pre></td></tr></table></figure>
<ul>
<li>摄像头</li>
</ul>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 显示所有声卡</span></span><br><span class="line">webcam list</span><br><span class="line"></span><br><span class="line"><span class="comment"># 设置摄像头</span></span><br><span class="line">webcam use xx</span><br></pre></td></tr></table></figure>
<ul>
<li>音视频编码</li>
</ul>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 音频编码</span></span><br><span class="line">codec list</span><br><span class="line"></span><br><span class="line"><span class="comment"># 视频编码</span></span><br><span class="line">vcodec list</span><br></pre></td></tr></table></figure>
<h3 id="遇到问题"><a href="#遇到问题" class="headerlink" title="遇到问题"></a>遇到问题</h3><ul>
<li>answer会导致崩溃</li>
</ul>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">--- a/coreapi/linphonecore.c</span><br><span class="line">+++ b/coreapi/linphonecore.c</span><br><span class="line">@@ <span class="number">-3731</span>,<span class="number">7</span> +<span class="number">3731</span>,<span class="number">7</span> @@ <span class="function"><span class="keyword">static</span> LinphoneCall * <span class="title">get_unique_call</span><span class="params">(LinphoneCore *lc)</span> </span>&#123;</span><br><span class="line"> &#125;</span><br><span class="line"></span><br><span class="line"> <span class="function">LinphoneStatus <span class="title">linphone_core_accept_call</span><span class="params">(LinphoneCore *lc, LinphoneCall *call)</span> </span>&#123;</span><br><span class="line">-       <span class="keyword">return</span> linphone_call_accept_with_params(call, <span class="literal">NULL</span>);</span><br><span class="line">+       <span class="keyword">return</span> linphone_core_accept_call_with_params(lc, call, <span class="literal">NULL</span>);</span><br><span class="line"> &#125;</span><br></pre></td></tr></table></figure>
<p>PS: 是由于官网源码BUG导致，可以按照此diff修复，再编译安装</p>
<ul>
<li>声卡选择</li>
</ul>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 设置播放声卡</span></span><br><span class="line">soundcard playback xx</span><br><span class="line"></span><br><span class="line"><span class="comment"># 设置录音声卡</span></span><br><span class="line">soundcard capture xx</span><br></pre></td></tr></table></figure>
<p>PS: 如果你的声卡录音和播放是分开，可以通过playback和record分别设置，这个在帮助文档中是找不到，但确实是有效</p>
<ul>
<li>支持摄像头</li>
</ul>
<p>首先必须加载v4l2</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo modprobe bcm2835-v4l2</span><br></pre></td></tr></table></figure>
<p>如果提示’No Devices’,则请在/boot/config.txt添加如下配置，并重启树莓派</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">start_x=1</span><br><span class="line">gpu_mem=128</span><br></pre></td></tr></table></figure>
<p>PS: 加载成功后，会在产生/dev/videox的文件，x可能是0 …</p>
<p>完成以上配置后，进入linphonec，使用<code>webcam list</code>就可以看到相应的选项，并进行设置</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">webcam use 1</span><br></pre></td></tr></table></figure>
<p>PS: 当然要开启视频支持，必须以 -C启动linphonec</p>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://smallmuou.gitee.io/blog/blog/2017/09/13/2017-09-13-map2cloud - 映射本地端口至云端/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="smallmuou">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/blog/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="smallmuou's blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/blog/2017/09/13/2017-09-13-map2cloud - 映射本地端口至云端/" itemprop="url">map2cloud - 映射本地端口至云端</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-09-13T00:00:00+08:00">
                2017-09-13
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/blog/categories/工具/" itemprop="url" rel="index">
                    <span itemprop="name">工具</span>
                  </a>
                </span>

                
                
              
            </span>
          

          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <blockquote>
<p>很多时候，我们需要远程访问本地的服务，一般我们是借助于Teamviewer或者花生壳，而这往往需要人在对方电脑旁，还有一点，无法真正做到本机操作，体验比较差；而借助该工具就可以直接将远端服务映射到云端，我们只需要访问云端对应端口就能访问远程服务。</p>
</blockquote>
<h3 id="准备"><a href="#准备" class="headerlink" title="准备"></a>准备</h3><p>在使用该工具，你至少需要准备一下几个内容</p>
<ul>
<li>装有sshd的云端主机</li>
<li>一台装有linux系统的本地主机</li>
</ul>
<h3 id="安装"><a href="#安装" class="headerlink" title="安装"></a>安装</h3><h4 id="1-安装依赖工具-autossh"><a href="#1-安装依赖工具-autossh" class="headerlink" title="1. 安装依赖工具 - autossh"></a>1. 安装依赖工具 - autossh</h4><p>可以使用yum或apt-get安装<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># centos</span></span><br><span class="line">yum install autossh</span><br><span class="line"></span><br><span class="line"><span class="comment"># debain</span></span><br><span class="line">apt-get install autossh</span><br></pre></td></tr></table></figure></p>
<p>如果以上方法无法安装，则请直接到<a href="http://www.harding.motd.ca/autossh/" target="_blank" rel="noopener">autossh官网</a>，下载源码并进行安装.</p>
<h4 id="2-安装map2cloud"><a href="#2-安装map2cloud" class="headerlink" title="2. 安装map2cloud"></a>2. 安装map2cloud</h4><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">sudo curl https://raw.githubusercontent.com/smallmuou/map2cloud/master/map2cloud &gt; /usr/<span class="built_in">local</span>/bin/map2cloud</span><br><span class="line">sudo chmod +x /usr/<span class="built_in">local</span>/bin/map2cloud</span><br></pre></td></tr></table></figure>
<h4 id="3-生成rsa密钥"><a href="#3-生成rsa密钥" class="headerlink" title="3. 生成rsa密钥"></a>3. 生成rsa密钥</h4><p>请使用ssh-keygen生成密钥对</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ssh-keygen -t rsa</span><br></pre></td></tr></table></figure>
<p>PS: 一路Enter就行，会在$Home/.ssh/下生成id_rsa和id_rsa.pub</p>
<h4 id="4-开启云端sshd的GatewayPorts功能"><a href="#4-开启云端sshd的GatewayPorts功能" class="headerlink" title="4. 开启云端sshd的GatewayPorts功能"></a>4. 开启云端sshd的GatewayPorts功能</h4><p>默认情况sshd是不开启GatewayPorts，这样无法外部访问.</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">vim /etc/ssh/sshd_config </span><br><span class="line"></span><br><span class="line">GatewayPorts yes</span><br><span class="line"></span><br><span class="line">保存退出后，重启sshd</span><br><span class="line"></span><br><span class="line">service sshd restart</span><br></pre></td></tr></table></figure>
<h3 id="使用"><a href="#使用" class="headerlink" title="使用"></a>使用</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">USAGE: map2cloud [OPTIONS] ssh-user@cloud-ip [local-ip:]local-port cloud-port</span><br><span class="line"></span><br><span class="line">DESCRIPTION:</span><br><span class="line">    ssh-user        The ssh user to access to cloud server.</span><br><span class="line">    cloud-ip        The cloud server ip or domain.</span><br><span class="line">    local-ip        The local ip to map, default is localhost.</span><br><span class="line">    local-port      The local port to map.</span><br><span class="line">    cloud-port      The port which local port to map to. note it must be an even number.</span><br><span class="line"></span><br><span class="line">OPTIONS:</span><br><span class="line">    -h              Show this help message and exit.</span><br><span class="line">    -i              Assign ssh private key path.</span><br><span class="line">    -p              Assign ssh port.</span><br><span class="line">    -n              Assign name of the service name.</span><br></pre></td></tr></table></figure>
<p>参数说明：</p>
<ul>
<li>ssh-user - 云端sshd用户</li>
<li>cloud-ip - 云端主机IP或域名</li>
<li>local-ip - 可选，本地主机IP，不填，则为localhost</li>
<li>local-port - 待映射的本地端口</li>
<li>cloud-port - 需要映射至云端的端口，必须偶数</li>
</ul>
<p>选项：</p>
<ul>
<li>-i 指定ssh私钥路径</li>
<li>-p 指定云端sshd端口，默认22</li>
<li>-n 指定本地服务名字，默认r-端口</li>
</ul>
<p>可以通过<code>map2cloud -h</code>查看详细的帮助</p>
<h3 id="例子"><a href="#例子" class="headerlink" title="例子"></a>例子</h3><ul>
<li>映射本机ssh服务端口22至云端22222</li>
</ul>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">map2cloud -i /root/.ssh/id_rsa -p 22 -n rssh root@your-cloud-ip 22 22222</span><br><span class="line">service rssh start</span><br></pre></td></tr></table></figure>
<p>PS：这样我执行要执行<code>ssh -p 22222 user@your-cloud-ip</code>，就可以访问本地主机</p>
<ul>
<li>映射192.168.12.100端口80至云端10080<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">map2cloud -n rhttp root@your-cloud-ip 192.168.12.100:80 10080</span><br><span class="line">service rhttp start</span><br></pre></td></tr></table></figure>
</li>
</ul>
<p>PS: 只需在浏览器下输入<a href="http://your-cloud-ip:10080，就可以访问本地服务" target="_blank" rel="noopener">http://your-cloud-ip:10080，就可以访问本地服务</a></p>
<h3 id="安全性"><a href="#安全性" class="headerlink" title="安全性"></a>安全性</h3><p>创建一个专门用于反向的用户</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">useradd -s /bin/<span class="literal">false</span> testxxxx</span><br></pre></td></tr></table></figure>
          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://smallmuou.gitee.io/blog/blog/2017/09/11/2017-09-11-window下自动切换IP脚本/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="smallmuou">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/blog/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="smallmuou's blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/blog/2017/09/11/2017-09-11-window下自动切换IP脚本/" itemprop="url">window下自动切换IP脚本</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-09-11T00:00:00+08:00">
                2017-09-11
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/blog/categories/运维/" itemprop="url" rel="index">
                    <span itemprop="name">运维</span>
                  </a>
                </span>

                
                
              
            </span>
          

          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>懒，就要懒到底; 工作中遇到一个坑点，存在两个网络环境，需要配置不同的IP才能访问，今天终于忍无可忍，把它自动化了，在未自动化前，我需要经历『打开网络和共享中心』-&gt; 『更改适配器设置』-&gt;『右键本地连接属性』-&gt; 『双击Ipv4』-&gt; 配置IP、子网掩码、网关，之后再插拔网线；在自动化之后，我只需要插拔网线，脚本会自动根据网络类型设置相应的IP。现在分享脚本如下</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br></pre></td><td class="code"><pre><span class="line">:: The script use to auto switch network ip </span><br><span class="line">:: Author: smallmuou</span><br><span class="line"></span><br><span class="line">@<span class="built_in">echo</span> off</span><br><span class="line"></span><br><span class="line">:Begin</span><br><span class="line"></span><br><span class="line"><span class="keyword">for</span> /f <span class="string">"tokens=2 delims=:"</span> %%i <span class="keyword">in</span> (<span class="string">'ipconfig^|findstr 默认网关'</span>) <span class="keyword">do</span> <span class="built_in">set</span> gw=%%i</span><br><span class="line">ping -n 1 %gw% &gt;nul</span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span> errorlevel 1 goto AutoConfig </span><br><span class="line"><span class="keyword">if</span> errorlevel 0 goto Continue</span><br><span class="line"></span><br><span class="line">:AutoConfig</span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span> <span class="string">"%gw%"</span> == <span class="string">" 192.168.12.1"</span> ( goto ConfigStarnet ) <span class="keyword">else</span> goto Config161</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">:ConfigStarnet</span><br><span class="line"></span><br><span class="line"><span class="built_in">echo</span> %time% switch to starnet ...</span><br><span class="line"></span><br><span class="line">netsh interface ip <span class="built_in">set</span> address 本地连接 static 192.168.60.152 255.255.255.0 192.168.60.1 </span><br><span class="line">goto Continue</span><br><span class="line"></span><br><span class="line">:Config161</span><br><span class="line"></span><br><span class="line"><span class="built_in">echo</span> %time% switch to 161 ...</span><br><span class="line"></span><br><span class="line">netsh interface ip <span class="built_in">set</span> address 本地连接 static 192.168.12.152 255.255.255.0 192.168.12.1</span><br><span class="line">goto Continue</span><br><span class="line"></span><br><span class="line">:Continue</span><br><span class="line"></span><br><span class="line"><span class="built_in">echo</span> %time% checking network ...</span><br><span class="line"></span><br><span class="line">::delay</span><br><span class="line">ping -n 10 127.0.0.1 &gt;nul </span><br><span class="line">goto Begin</span><br></pre></td></tr></table></figure>
          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://smallmuou.gitee.io/blog/blog/2017/09/11/2017-09-11-如何解决域名访问腾讯云-该网站暂时无法访问-问题/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="smallmuou">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/blog/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="smallmuou's blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/blog/2017/09/11/2017-09-11-如何解决域名访问腾讯云-该网站暂时无法访问-问题/" itemprop="url">如何解决域名访问腾讯云-该网站暂时无法访问-问题</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-09-11T00:00:00+08:00">
                2017-09-11
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/blog/categories/运维/" itemprop="url" rel="index">
                    <span itemprop="name">运维</span>
                  </a>
                </span>

                
                
              
            </span>
          

          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>最近访问腾讯云服务器突然提示”该网站暂时无法访问”，列出了3点原因，后面去腾讯云论坛查了下，说需要在腾讯云这边备案的域名才可以访问腾讯云服务器，相当坑，而我域名是阿里云的，这是强制捆绑买卖。考虑到域名迁移的麻烦性，本文给出了在不迁移域名的情况下的解决思路</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">温馨提示：该网站暂时无法访问</span><br><span class="line">原因一：根据 工信部相关法律法规，该网站尚未备案；</span><br><span class="line">原因二：根据 工信部相关法律法规，该网站未在接入商腾讯云上备案；</span><br><span class="line">原因三：该网站可能存在不适宜传播的信息。</span><br><span class="line"></span><br><span class="line">本页面为默认提示页面，如存在以上问题，请联系网站负责人及时处理。</span><br><span class="line">如需备案请登录 腾讯云备案控制台，查看 备案常见问题，谢谢合作！</span><br></pre></td></tr></table></figure>
<h2 id="1-通过IP访问"><a href="#1-通过IP访问" class="headerlink" title="1. 通过IP访问"></a>1. 通过IP访问</h2><p>经过实际测试，发现可以使用IP访问</p>
<h2 id="2-修改Host"><a href="#2-修改Host" class="headerlink" title="2. 修改Host"></a>2. 修改Host</h2><p>访问时，将HTTP头的Host字段改为IP即可</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">curl -H <span class="string">"Host: 127.0.0.1"</span> xxx.xxx.xxx.xxx</span><br></pre></td></tr></table></figure>
<h2 id="3-通过反向代理"><a href="#3-通过反向代理" class="headerlink" title="3. 通过反向代理"></a>3. 通过反向代理</h2><p>可以通过一台正常可以域名访问的服务器（比如阿里），添加二级域名，并指向该服务器，由该服务器反向至腾讯云服务器，关于反向代理，可以查考我之前的文章 <a href="/linux/2017/08/24/linux下nginx反向代理配置.html">linux下nginx反向代理配置</a></p>
<p>总结，其实真正有效的解决方案是通过反向代理来实现，当然前提必须要有一个可以正常访问的服务器.</p>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://smallmuou.gitee.io/blog/blog/2017/09/07/2017-09-07-asterisk配置mysql来保存peers/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="smallmuou">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/blog/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="smallmuou's blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/blog/2017/09/07/2017-09-07-asterisk配置mysql来保存peers/" itemprop="url">asterisk配置mysql来保存peers</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-09-07T00:00:00+08:00">
                2017-09-07
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/blog/categories/音视频/" itemprop="url" rel="index">
                    <span itemprop="name">音视频</span>
                  </a>
                </span>

                
                
              
            </span>
          

          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>asterisk是一个开源的sip服务器，默认情况，asterisk是从sip.conf来配置peers，如果peers有变更或者数量比较大，就不能采用这种方式，asterisk提供的realtime方式，支持数据库实时保存及读取peers，数据库支持mysql、sqlite、postgres等，本文将指导如何进行mysql配置.</p>
<h4 id="步骤1-安装并配置mysql"><a href="#步骤1-安装并配置mysql" class="headerlink" title="步骤1 - 安装并配置mysql"></a>步骤1 - 安装并配置mysql</h4><p>可以参考其他文档安装mysql，并配置用户密码</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">mysqladmin -uroot password <span class="string">'new password'</span></span><br></pre></td></tr></table></figure>
<h4 id="步骤2-创建数据库及表"><a href="#步骤2-创建数据库及表" class="headerlink" title="步骤2 - 创建数据库及表"></a>步骤2 - 创建数据库及表</h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">CREATE</span> <span class="keyword">DATABASE</span> asterisk;</span><br><span class="line"><span class="keyword">CREATE</span> <span class="keyword">TABLE</span> <span class="keyword">IF</span> <span class="keyword">NOT</span> <span class="keyword">EXISTS</span> <span class="string">`sippeers`</span> (</span><br><span class="line">      <span class="string">`id`</span> <span class="built_in">int</span>(<span class="number">11</span>) <span class="keyword">NOT</span> <span class="literal">NULL</span> AUTO_INCREMENT,</span><br><span class="line">      <span class="string">`name`</span> <span class="built_in">varchar</span>(<span class="number">10</span>) <span class="keyword">NOT</span> <span class="literal">NULL</span>,</span><br><span class="line">      <span class="string">`ipaddr`</span> <span class="built_in">varchar</span>(<span class="number">15</span>) <span class="keyword">DEFAULT</span> <span class="literal">NULL</span>,</span><br><span class="line">      <span class="string">`port`</span> <span class="built_in">int</span>(<span class="number">5</span>) <span class="keyword">DEFAULT</span> <span class="literal">NULL</span>,</span><br><span class="line">      <span class="string">`regseconds`</span> <span class="built_in">int</span>(<span class="number">11</span>) <span class="keyword">DEFAULT</span> <span class="literal">NULL</span>,</span><br><span class="line">      <span class="string">`defaultuser`</span> <span class="built_in">varchar</span>(<span class="number">10</span>) <span class="keyword">DEFAULT</span> <span class="literal">NULL</span>,</span><br><span class="line">      <span class="string">`fullcontact`</span> <span class="built_in">varchar</span>(<span class="number">64</span>) <span class="keyword">DEFAULT</span> <span class="literal">NULL</span>,</span><br><span class="line">      <span class="string">`regserver`</span> <span class="built_in">varchar</span>(<span class="number">20</span>) <span class="keyword">DEFAULT</span> <span class="literal">NULL</span>,</span><br><span class="line">      <span class="string">`useragent`</span> <span class="built_in">varchar</span>(<span class="number">64</span>) <span class="keyword">DEFAULT</span> <span class="literal">NULL</span>,</span><br><span class="line">      <span class="string">`lastms`</span> <span class="built_in">int</span>(<span class="number">11</span>) <span class="keyword">DEFAULT</span> <span class="literal">NULL</span>,</span><br><span class="line">      <span class="string">`host`</span> <span class="built_in">varchar</span>(<span class="number">40</span>) <span class="keyword">DEFAULT</span> <span class="literal">NULL</span>,</span><br><span class="line">      <span class="string">`type`</span> enum(<span class="string">'friend'</span>,<span class="string">'user'</span>,<span class="string">'peer'</span>) <span class="keyword">DEFAULT</span> <span class="literal">NULL</span>,</span><br><span class="line">      <span class="string">`context`</span> <span class="built_in">varchar</span>(<span class="number">40</span>) <span class="keyword">DEFAULT</span> <span class="literal">NULL</span>,</span><br><span class="line">      <span class="string">`permit`</span> <span class="built_in">varchar</span>(<span class="number">40</span>) <span class="keyword">DEFAULT</span> <span class="literal">NULL</span>,</span><br><span class="line">      <span class="string">`deny`</span> <span class="built_in">varchar</span>(<span class="number">40</span>) <span class="keyword">DEFAULT</span> <span class="literal">NULL</span>,</span><br><span class="line">      <span class="string">`secret`</span> <span class="built_in">varchar</span>(<span class="number">40</span>) <span class="keyword">DEFAULT</span> <span class="literal">NULL</span>,</span><br><span class="line">      <span class="string">`md5secret`</span> <span class="built_in">varchar</span>(<span class="number">40</span>) <span class="keyword">DEFAULT</span> <span class="literal">NULL</span>,</span><br><span class="line">      <span class="string">`remotesecret`</span> <span class="built_in">varchar</span>(<span class="number">40</span>) <span class="keyword">DEFAULT</span> <span class="literal">NULL</span>,</span><br><span class="line">      <span class="string">`transport`</span> enum(<span class="string">'udp'</span>,<span class="string">'tcp'</span>,<span class="string">'udp,tcp'</span>,<span class="string">'tcp,udp'</span>) <span class="keyword">DEFAULT</span> <span class="literal">NULL</span>,</span><br><span class="line">      <span class="string">`dtmfmode`</span> enum(<span class="string">'rfc2833'</span>,<span class="string">'info'</span>,<span class="string">'shortinfo'</span>,<span class="string">'inband'</span>,<span class="string">'auto'</span>) <span class="keyword">DEFAULT</span> <span class="literal">NULL</span>,</span><br><span class="line">      <span class="string">`directmedia`</span> enum(<span class="string">'yes'</span>,<span class="string">'no'</span>,<span class="string">'nonat'</span>,<span class="string">'update'</span>) <span class="keyword">DEFAULT</span> <span class="literal">NULL</span>,</span><br><span class="line">      <span class="string">`nat`</span> enum(<span class="string">'yes'</span>,<span class="string">'no'</span>,<span class="string">'never'</span>,<span class="string">'route'</span>) <span class="keyword">DEFAULT</span> <span class="literal">NULL</span>,</span><br><span class="line">      <span class="string">`callgroup`</span> <span class="built_in">varchar</span>(<span class="number">40</span>) <span class="keyword">DEFAULT</span> <span class="literal">NULL</span>,</span><br><span class="line">      <span class="string">`pickupgroup`</span> <span class="built_in">varchar</span>(<span class="number">40</span>) <span class="keyword">DEFAULT</span> <span class="literal">NULL</span>,</span><br><span class="line">      <span class="string">`language`</span> <span class="built_in">varchar</span>(<span class="number">40</span>) <span class="keyword">DEFAULT</span> <span class="literal">NULL</span>,</span><br><span class="line">      <span class="string">`allow`</span> <span class="built_in">varchar</span>(<span class="number">40</span>) <span class="keyword">DEFAULT</span> <span class="literal">NULL</span>,</span><br><span class="line">      <span class="string">`disallow`</span> <span class="built_in">varchar</span>(<span class="number">40</span>) <span class="keyword">DEFAULT</span> <span class="literal">NULL</span>,</span><br><span class="line">      <span class="string">`insecure`</span> <span class="built_in">varchar</span>(<span class="number">40</span>) <span class="keyword">DEFAULT</span> <span class="literal">NULL</span>,</span><br><span class="line">      <span class="string">`trustrpid`</span> enum(<span class="string">'yes'</span>,<span class="string">'no'</span>) <span class="keyword">DEFAULT</span> <span class="literal">NULL</span>,</span><br><span class="line">      <span class="string">`progressinband`</span> enum(<span class="string">'yes'</span>,<span class="string">'no'</span>,<span class="string">'never'</span>) <span class="keyword">DEFAULT</span> <span class="literal">NULL</span>,</span><br><span class="line">      <span class="string">`promiscredir`</span> enum(<span class="string">'yes'</span>,<span class="string">'no'</span>) <span class="keyword">DEFAULT</span> <span class="literal">NULL</span>,</span><br><span class="line">      <span class="string">`useclientcode`</span> enum(<span class="string">'yes'</span>,<span class="string">'no'</span>) <span class="keyword">DEFAULT</span> <span class="literal">NULL</span>,</span><br><span class="line">      <span class="string">`accountcode`</span> <span class="built_in">varchar</span>(<span class="number">40</span>) <span class="keyword">DEFAULT</span> <span class="literal">NULL</span>,</span><br><span class="line">      <span class="string">`setvar`</span> <span class="built_in">varchar</span>(<span class="number">40</span>) <span class="keyword">DEFAULT</span> <span class="literal">NULL</span>,</span><br><span class="line">      <span class="string">`callerid`</span> <span class="built_in">varchar</span>(<span class="number">40</span>) <span class="keyword">DEFAULT</span> <span class="literal">NULL</span>,</span><br><span class="line">      <span class="string">`amaflags`</span> <span class="built_in">varchar</span>(<span class="number">40</span>) <span class="keyword">DEFAULT</span> <span class="literal">NULL</span>,</span><br><span class="line">      <span class="string">`callcounter`</span> enum(<span class="string">'yes'</span>,<span class="string">'no'</span>) <span class="keyword">DEFAULT</span> <span class="literal">NULL</span>,</span><br><span class="line">      <span class="string">`busylevel`</span> <span class="built_in">int</span>(<span class="number">11</span>) <span class="keyword">DEFAULT</span> <span class="literal">NULL</span>,</span><br><span class="line">      <span class="string">`allowoverlap`</span> enum(<span class="string">'yes'</span>,<span class="string">'no'</span>) <span class="keyword">DEFAULT</span> <span class="literal">NULL</span>,</span><br><span class="line">      <span class="string">`allowsubscribe`</span> enum(<span class="string">'yes'</span>,<span class="string">'no'</span>) <span class="keyword">DEFAULT</span> <span class="literal">NULL</span>,</span><br><span class="line">      <span class="string">`videosupport`</span> enum(<span class="string">'yes'</span>,<span class="string">'no'</span>) <span class="keyword">DEFAULT</span> <span class="literal">NULL</span>,</span><br><span class="line">      <span class="string">`maxcallbitrate`</span> <span class="built_in">int</span>(<span class="number">11</span>) <span class="keyword">DEFAULT</span> <span class="literal">NULL</span>,</span><br><span class="line">      <span class="string">`rfc2833compensate`</span> enum(<span class="string">'yes'</span>,<span class="string">'no'</span>) <span class="keyword">DEFAULT</span> <span class="literal">NULL</span>,</span><br><span class="line">      <span class="string">`mailbox`</span> <span class="built_in">varchar</span>(<span class="number">40</span>) <span class="keyword">DEFAULT</span> <span class="literal">NULL</span>,</span><br><span class="line">      <span class="string">`session-timers`</span> enum(<span class="string">'accept'</span>,<span class="string">'refuse'</span>,<span class="string">'originate'</span>) <span class="keyword">DEFAULT</span> <span class="literal">NULL</span>,</span><br><span class="line">      <span class="string">`session-expires`</span> <span class="built_in">int</span>(<span class="number">11</span>) <span class="keyword">DEFAULT</span> <span class="literal">NULL</span>,</span><br><span class="line">      <span class="string">`session-minse`</span> <span class="built_in">int</span>(<span class="number">11</span>) <span class="keyword">DEFAULT</span> <span class="literal">NULL</span>,</span><br><span class="line">      <span class="string">`session-refresher`</span> enum(<span class="string">'uac'</span>,<span class="string">'uas'</span>) <span class="keyword">DEFAULT</span> <span class="literal">NULL</span>,</span><br><span class="line">      <span class="string">`t38pt_usertpsource`</span> <span class="built_in">varchar</span>(<span class="number">40</span>) <span class="keyword">DEFAULT</span> <span class="literal">NULL</span>,</span><br><span class="line">      <span class="string">`regexten`</span> <span class="built_in">varchar</span>(<span class="number">40</span>) <span class="keyword">DEFAULT</span> <span class="literal">NULL</span>,</span><br><span class="line">      <span class="string">`fromdomain`</span> <span class="built_in">varchar</span>(<span class="number">40</span>) <span class="keyword">DEFAULT</span> <span class="literal">NULL</span>,</span><br><span class="line">      <span class="string">`fromuser`</span> <span class="built_in">varchar</span>(<span class="number">40</span>) <span class="keyword">DEFAULT</span> <span class="literal">NULL</span>,</span><br><span class="line">      <span class="string">`qualify`</span> <span class="built_in">varchar</span>(<span class="number">40</span>) <span class="keyword">DEFAULT</span> <span class="literal">NULL</span>,</span><br><span class="line">      <span class="string">`defaultip`</span> <span class="built_in">varchar</span>(<span class="number">40</span>) <span class="keyword">DEFAULT</span> <span class="literal">NULL</span>,</span><br><span class="line">      <span class="string">`rtptimeout`</span> <span class="built_in">int</span>(<span class="number">11</span>) <span class="keyword">DEFAULT</span> <span class="literal">NULL</span>,</span><br><span class="line">      <span class="string">`rtpholdtimeout`</span> <span class="built_in">int</span>(<span class="number">11</span>) <span class="keyword">DEFAULT</span> <span class="literal">NULL</span>,</span><br><span class="line">      <span class="string">`sendrpid`</span> enum(<span class="string">'yes'</span>,<span class="string">'no'</span>) <span class="keyword">DEFAULT</span> <span class="literal">NULL</span>,</span><br><span class="line">      <span class="string">`outboundproxy`</span> <span class="built_in">varchar</span>(<span class="number">40</span>) <span class="keyword">DEFAULT</span> <span class="literal">NULL</span>,</span><br><span class="line">      <span class="string">`callbackextension`</span> <span class="built_in">varchar</span>(<span class="number">40</span>) <span class="keyword">DEFAULT</span> <span class="literal">NULL</span>,</span><br><span class="line">      <span class="string">`registertrying`</span> enum(<span class="string">'yes'</span>,<span class="string">'no'</span>) <span class="keyword">DEFAULT</span> <span class="literal">NULL</span>,</span><br><span class="line">      <span class="string">`timert1`</span> <span class="built_in">int</span>(<span class="number">11</span>) <span class="keyword">DEFAULT</span> <span class="literal">NULL</span>,</span><br><span class="line">      <span class="string">`timerb`</span> <span class="built_in">int</span>(<span class="number">11</span>) <span class="keyword">DEFAULT</span> <span class="literal">NULL</span>,</span><br><span class="line">      <span class="string">`qualifyfreq`</span> <span class="built_in">int</span>(<span class="number">11</span>) <span class="keyword">DEFAULT</span> <span class="literal">NULL</span>,</span><br><span class="line">      <span class="string">`constantssrc`</span> enum(<span class="string">'yes'</span>,<span class="string">'no'</span>) <span class="keyword">DEFAULT</span> <span class="literal">NULL</span>,</span><br><span class="line">      <span class="string">`contactpermit`</span> <span class="built_in">varchar</span>(<span class="number">40</span>) <span class="keyword">DEFAULT</span> <span class="literal">NULL</span>,</span><br><span class="line">      <span class="string">`contactdeny`</span> <span class="built_in">varchar</span>(<span class="number">40</span>) <span class="keyword">DEFAULT</span> <span class="literal">NULL</span>,</span><br><span class="line">      <span class="string">`usereqphone`</span> enum(<span class="string">'yes'</span>,<span class="string">'no'</span>) <span class="keyword">DEFAULT</span> <span class="literal">NULL</span>,</span><br><span class="line">      <span class="string">`textsupport`</span> enum(<span class="string">'yes'</span>,<span class="string">'no'</span>) <span class="keyword">DEFAULT</span> <span class="literal">NULL</span>,</span><br><span class="line">      <span class="string">`faxdetect`</span> enum(<span class="string">'yes'</span>,<span class="string">'no'</span>) <span class="keyword">DEFAULT</span> <span class="literal">NULL</span>,</span><br><span class="line">      <span class="string">`buggymwi`</span> enum(<span class="string">'yes'</span>,<span class="string">'no'</span>) <span class="keyword">DEFAULT</span> <span class="literal">NULL</span>,</span><br><span class="line">      <span class="string">`auth`</span> <span class="built_in">varchar</span>(<span class="number">40</span>) <span class="keyword">DEFAULT</span> <span class="literal">NULL</span>,</span><br><span class="line">      <span class="string">`fullname`</span> <span class="built_in">varchar</span>(<span class="number">40</span>) <span class="keyword">DEFAULT</span> <span class="literal">NULL</span>,</span><br><span class="line">      <span class="string">`trunkname`</span> <span class="built_in">varchar</span>(<span class="number">40</span>) <span class="keyword">DEFAULT</span> <span class="literal">NULL</span>,</span><br><span class="line">      <span class="string">`cid_number`</span> <span class="built_in">varchar</span>(<span class="number">40</span>) <span class="keyword">DEFAULT</span> <span class="literal">NULL</span>,</span><br><span class="line">      <span class="string">`callingpres`</span> enum(<span class="string">'allowed_not_screened'</span>,<span class="string">'allowed_passed_screen'</span>,<span class="string">'allowed_failed_screen'</span>,<span class="string">'allowed'</span>,<span class="string">'prohib_not_screened'</span>,<span class="string">'prohib_passed_screen'</span>,<span class="string">'prohib_failed_screen'</span>,<span class="string">'prohib'</span>) <span class="keyword">DEFAULT</span> <span class="literal">NULL</span>,</span><br><span class="line">      <span class="string">`mohinterpret`</span> <span class="built_in">varchar</span>(<span class="number">40</span>) <span class="keyword">DEFAULT</span> <span class="literal">NULL</span>,</span><br><span class="line">      <span class="string">`mohsuggest`</span> <span class="built_in">varchar</span>(<span class="number">40</span>) <span class="keyword">DEFAULT</span> <span class="literal">NULL</span>,</span><br><span class="line">      <span class="string">`parkinglot`</span> <span class="built_in">varchar</span>(<span class="number">40</span>) <span class="keyword">DEFAULT</span> <span class="literal">NULL</span>,</span><br><span class="line">      <span class="string">`hasvoicemail`</span> enum(<span class="string">'yes'</span>,<span class="string">'no'</span>) <span class="keyword">DEFAULT</span> <span class="literal">NULL</span>,</span><br><span class="line">      <span class="string">`subscribemwi`</span> enum(<span class="string">'yes'</span>,<span class="string">'no'</span>) <span class="keyword">DEFAULT</span> <span class="literal">NULL</span>,</span><br><span class="line">      <span class="string">`vmexten`</span> <span class="built_in">varchar</span>(<span class="number">40</span>) <span class="keyword">DEFAULT</span> <span class="literal">NULL</span>,</span><br><span class="line">      <span class="string">`autoframing`</span> enum(<span class="string">'yes'</span>,<span class="string">'no'</span>) <span class="keyword">DEFAULT</span> <span class="literal">NULL</span>,</span><br><span class="line">      <span class="string">`rtpkeepalive`</span> <span class="built_in">int</span>(<span class="number">11</span>) <span class="keyword">DEFAULT</span> <span class="literal">NULL</span>,</span><br><span class="line">      <span class="string">`call-limit`</span> <span class="built_in">int</span>(<span class="number">11</span>) <span class="keyword">DEFAULT</span> <span class="literal">NULL</span>,</span><br><span class="line">      <span class="string">`g726nonstandard`</span> enum(<span class="string">'yes'</span>,<span class="string">'no'</span>) <span class="keyword">DEFAULT</span> <span class="literal">NULL</span>,</span><br><span class="line">      <span class="string">`ignoresdpversion`</span> enum(<span class="string">'yes'</span>,<span class="string">'no'</span>) <span class="keyword">DEFAULT</span> <span class="literal">NULL</span>,</span><br><span class="line">      <span class="string">`allowtransfer`</span> enum(<span class="string">'yes'</span>,<span class="string">'no'</span>) <span class="keyword">DEFAULT</span> <span class="literal">NULL</span>,</span><br><span class="line">      <span class="string">`dynamic`</span> enum(<span class="string">'yes'</span>,<span class="string">'no'</span>) <span class="keyword">DEFAULT</span> <span class="literal">NULL</span>,</span><br><span class="line">      PRIMARY <span class="keyword">KEY</span> (<span class="string">`id`</span>),</span><br><span class="line">      <span class="keyword">UNIQUE</span> <span class="keyword">KEY</span> <span class="string">`name`</span> (<span class="string">`name`</span>),</span><br><span class="line">      <span class="keyword">KEY</span> <span class="string">`ipaddr`</span> (<span class="string">`ipaddr`</span>,<span class="string">`port`</span>),</span><br><span class="line">      <span class="keyword">KEY</span> <span class="string">`host`</span> (<span class="string">`host`</span>,<span class="string">`port`</span>)</span><br><span class="line">) <span class="keyword">ENGINE</span>=MyISAM;</span><br></pre></td></tr></table></figure>
<h4 id="步骤3-编译asterisk的mysql模块"><a href="#步骤3-编译asterisk的mysql模块" class="headerlink" title="步骤3 - 编译asterisk的mysql模块"></a>步骤3 - 编译asterisk的mysql模块</h4><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">make menuconfig</span><br></pre></td></tr></table></figure>
<p>勾选 addons-&gt;res_config_mysql，并重新make &amp;&amp; make install</p>
<h4 id="步骤4-配置res-config-mysql-conf"><a href="#步骤4-配置res-config-mysql-conf" class="headerlink" title="步骤4 - 配置res_config_mysql.conf"></a>步骤4 - 配置res_config_mysql.conf</h4><p>vim /etc/asterisk/res_config_mysql.conf<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">[general]</span><br><span class="line">dbhost = 127.0.0.1</span><br><span class="line">dbname = asterisk</span><br><span class="line">dbuser = root</span><br><span class="line">dbpass = 123456</span><br><span class="line">dbport = 3306</span><br><span class="line">dbsock = /var/lib/mysql/mysql.sock</span><br><span class="line">dbcharset = utf8</span><br></pre></td></tr></table></figure></p>
<p>ps: dbname数据库名字， dbsock为mysql的本地sock文件，需要根据自己环境变更</p>
<h4 id="步骤5-配置extconfig-conf"><a href="#步骤5-配置extconfig-conf" class="headerlink" title="步骤5 - 配置extconfig.conf"></a>步骤5 - 配置extconfig.conf</h4><p>vim /etc/asterisk/extconfig.conf<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sippeers =&gt; mysql,general,sippeers</span><br></pre></td></tr></table></figure></p>
<p>ps: general是对应res_config_mysql.conf的段名（中括号部分）， sippeers为数据库表名</p>
<h4 id="步骤6-插入用户信息"><a href="#步骤6-插入用户信息" class="headerlink" title="步骤6 - 插入用户信息"></a>步骤6 - 插入用户信息</h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">INSERT</span> <span class="keyword">INTO</span> sippeers (<span class="keyword">name</span>, host, secret) <span class="keyword">values</span> (<span class="string">'111'</span>, <span class="string">'dynamic'</span>, <span class="string">'111'</span>);</span><br></pre></td></tr></table></figure>
<p>ps: name用户名，secret密码，host必须指定为dynamic，否则注册不了</p>
<h4 id="步骤7-启动asterisk"><a href="#步骤7-启动asterisk" class="headerlink" title="步骤7 - 启动asterisk"></a>步骤7 - 启动asterisk</h4><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">asterisk</span><br></pre></td></tr></table></figure>
<p>此时就可以正常注册了，客户端的一些信息就会更新到mysql，如果发现未更新，说明可能更新失败，请查看asterisk控制台的报错信息，一般是某些字段长度超出了mysql表定义的长度。</p>
<p>以上是我配置的整个过程，当然中间踩了很多坑，不过都可以通过asterisk控制台找出具体原因.s</p>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://smallmuou.gitee.io/blog/blog/2017/09/05/2017-09-05-快速展现和保存16进制/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="smallmuou">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/blog/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="smallmuou's blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/blog/2017/09/05/2017-09-05-快速展现和保存16进制/" itemprop="url">快速展现和保存16进制</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-09-05T00:00:00+08:00">
                2017-09-05
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/blog/categories/工具/" itemprop="url" rel="index">
                    <span itemprop="name">工具</span>
                  </a>
                </span>

                
                
              
            </span>
          

          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>经常会遇到一些16进制文本”70 e7 2c  cd 52 87 d0 c7 c0 8a 1a”，如何展现和保存这些内容，今天为大家介绍一个工具xxd. 通过这个语句<code>echo &#39;70 e7 2c  cd 52 87 d0 c7 c0 8a 1a&#39; | xxd -r -p &gt; out</code>，就能把”70 e7 …”保存至out文件.</p>
<h4 id="xxd用法"><a href="#xxd用法" class="headerlink" title="xxd用法"></a>xxd用法</h4><p>xxd - 展现文件的16进制或将16进制转换成文件</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">xxd [options] [infile [outfile]]</span><br><span class="line">xxd -r[evert] [options] [infile [outfile]]</span><br><span class="line"></span><br><span class="line">常用options：</span><br><span class="line"></span><br><span class="line">-b - 二进制展现</span><br><span class="line">-g - 多少字节为一个单元</span><br><span class="line">-c - 一行显示多少单元</span><br><span class="line">-i - c语言方式展现，<span class="string">"0x01, 0x02, ..."</span></span><br><span class="line">-p - 文本展现</span><br><span class="line">-r - 写入16进制</span><br></pre></td></tr></table></figure>
<h4 id="例子"><a href="#例子" class="headerlink" title="例子"></a>例子</h4><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 保存16进制</span></span><br><span class="line"><span class="built_in">echo</span> <span class="string">"0x31, 0x32"</span>|xxd -r -p &gt; <span class="built_in">test</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 展现16进制</span></span><br><span class="line">xxd <span class="built_in">test</span></span><br></pre></td></tr></table></figure>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://smallmuou.gitee.io/blog/blog/2017/09/05/2017-09-05-通过tcpdump抓包分析ETHERNET-IP-TCP-UDP包结构/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="smallmuou">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/blog/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="smallmuou's blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/blog/2017/09/05/2017-09-05-通过tcpdump抓包分析ETHERNET-IP-TCP-UDP包结构/" itemprop="url">通过tcpdump抓包分析ETHERNET-IP-TCP-UDP包结构</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-09-05T00:00:00+08:00">
                2017-09-05
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/blog/categories/运维/" itemprop="url" rel="index">
                    <span itemprop="name">运维</span>
                  </a>
                </span>

                
                
              
            </span>
          

          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>抓包是学习网络协议的有效途径，通过实际分析，使得”理论”不那么枯燥，本文会通过抓包来分析各类包结构。</p>
<p>为了方便理解，大家需要先有以下概念：</p>
<ul>
<li>TCP包结构 - [ ETHERNET头 [ IP头 [ TCP头 [ DATA ] ] ] ]</li>
<li>UDP包结构 - [ ETHERNET头 [ IP头 [ UDP头 [ DATA ] ] ] ]</li>
</ul>
<p>有了以上概念，下面放上我抓取的TCP包（HTTP）</p>
<p>sudo tcpdump -i en0 port 80 -xx</p>
<pre>
17:17:29.484811 IP 192.168.12.101.63895 > 119.29.177.26.http: Flags [P.], seq 1:80, ack 1, win 4103, options [nop,nop,TS val 53585color3116 ecr 3024973830], length 79: HTTP: GET / HTTP/1.1
    0x0000:  <font color="#E97D00">d0c7 c08a 1a7c 6003 0899 962a 0800</font> <font color="#03AF59">4500
    0x0010:  0083 68c9 4000 4006 dc66 c0a8 0c65 771d
    0x0020:  b11a</font> <font color="#55A8E7">f997 0050 6046 44fe ae85 07c8 8018
    0x0030:  1007 21bd 0000 0101 080a 1ff0 783c b44d
    0x0040:  7006</font> 4745 5420 2f20 4854 5450 2f31 2e31
    0x0050:  0d0a 486f 7374 3a20 7777 772e 762d 6a75
    0x0060:  2e63 6f6d 2e63 6e0d 0a55 7365 722d 4167
    0x0070:  656e 743a 2063 7572 6c2f 372e 3531 2e30
    0x0080:  0d0a 4163 6365 7074 3a20 2a2f 2a0d 0a0d
    0x0090:  0a
</pre>

<h4 id="ETHERNET头"><a href="#ETHERNET头" class="headerlink" title="ETHERNET头"></a><font color="#E97D00">ETHERNET头</font></h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"> 0                   1                   2</span><br><span class="line"> 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3</span><br><span class="line">+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+</span><br><span class="line">|            Destination Mac(6Bytes)            |</span><br><span class="line">|                                               |</span><br><span class="line">+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+</span><br><span class="line">|              Source Mac (6Bytes)              |</span><br><span class="line">|                                               |</span><br><span class="line">+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+</span><br><span class="line">|     Type(2Bytes)  |</span><br><span class="line">+-+-+-+-+-+-+-+-+-+-+</span><br></pre></td></tr></table></figure>
<table>
<thead>
<tr>
<th style="text-align:left">字段</th>
<th style="text-align:left">说明</th>
<th style="text-align:left">实际值</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left">Destination Mac</td>
<td style="text-align:left">目的MAC</td>
<td style="text-align:left">d0c7 c08a = d0:c7:c0:8a:1a:7c</td>
</tr>
<tr>
<td style="text-align:left">Source Mac</td>
<td style="text-align:left">源MAC</td>
<td style="text-align:left">1a7c 6003 = 60:03:08:99:96:2a</td>
</tr>
<tr>
<td style="text-align:left">Type</td>
<td style="text-align:left">类型</td>
<td style="text-align:left">0800</td>
</tr>
</tbody>
</table>
<h4 id="IP头"><a href="#IP头" class="headerlink" title="IP头"></a><font color="#03AF59">IP头</font></h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"> 0                   1                   2                   3</span><br><span class="line"> 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1</span><br><span class="line">+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+</span><br><span class="line">|Version|  IHL  |Type of Service|          Total Length         |</span><br><span class="line">+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+</span><br><span class="line">|         Identification        |Flags|      Fragment Offset    |</span><br><span class="line">+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+</span><br><span class="line">|  Time to Live |    Protocol   |         Header Checksum       |</span><br><span class="line">+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+</span><br><span class="line">|                       Source Address                          |</span><br><span class="line">+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+</span><br><span class="line">|                    Destination Address                        |</span><br><span class="line">+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+</span><br><span class="line">|                    Options                    |    Padding    |</span><br><span class="line">+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+</span><br></pre></td></tr></table></figure>
<table>
<thead>
<tr>
<th style="text-align:left">字段</th>
<th style="text-align:left">说明</th>
<th style="text-align:left">实际值</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left">Version</td>
<td style="text-align:left">IP版本</td>
<td style="text-align:left">4</td>
</tr>
<tr>
<td style="text-align:left">IHL</td>
<td style="text-align:left">IP头部长度（单元4字节）</td>
<td style="text-align:left">5，即5x4=20字节</td>
</tr>
<tr>
<td style="text-align:left">Total Length</td>
<td style="text-align:left">IP数据包总长度，最长65535，即为何需要IP分片</td>
<td style="text-align:left">0x0083 = 131 = 20（IP头）+ 32（TCP头）+ 79（实际数据)</td>
</tr>
<tr>
<td style="text-align:left">Protocol</td>
<td style="text-align:left">协议号<br>1    ICMP<br>2    IGMP<br>6    TCP<br>17    UDP</td>
<td style="text-align:left">6 即TCP</td>
</tr>
<tr>
<td style="text-align:left">Time to Live</td>
<td style="text-align:left">存活数，每过一次路由减1，到0后停止路由</td>
<td style="text-align:left">0x40，即64</td>
</tr>
<tr>
<td style="text-align:left">Source Address</td>
<td style="text-align:left">原IP地址</td>
<td style="text-align:left">c0a8 0c65 = c0.a8.0c.65 = 192.168.12.101</td>
</tr>
<tr>
<td style="text-align:left">Destination Address</td>
<td style="text-align:left">目的IP地址</td>
<td style="text-align:left">771d b11a = 77.1d.b1.1a = 119.29.177.26</td>
</tr>
</tbody>
</table>
<h4 id="TCP头"><a href="#TCP头" class="headerlink" title="TCP头"></a><font color="#55A8E7">TCP头</font></h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line"> 0                   1                   2                   3</span><br><span class="line"> 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1</span><br><span class="line">+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+</span><br><span class="line">|          Source Port          |       Destination Port        |</span><br><span class="line">+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+</span><br><span class="line">|                        Sequence Number                        |</span><br><span class="line">+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+</span><br><span class="line">|                    Acknowledgment Number                      |</span><br><span class="line">+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+</span><br><span class="line">|  Data |           |U|A|P|R|S|F|                               |</span><br><span class="line">| Offset| Reserved  |R|C|S|S|Y|I|            Window             |</span><br><span class="line">|       |           |G|K|H|T|N|N|                               |</span><br><span class="line">+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+</span><br><span class="line">|           Checksum            |         Urgent Pointer        |</span><br><span class="line">+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+</span><br><span class="line">|                    Options                    |    Padding    |</span><br><span class="line">+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+</span><br><span class="line">|                             data                              |</span><br><span class="line">+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+</span><br></pre></td></tr></table></figure>
<table>
<thead>
<tr>
<th style="text-align:left">字段</th>
<th style="text-align:left">说明</th>
<th style="text-align:left">实际值</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left">Source Port</td>
<td style="text-align:left">原端口</td>
<td style="text-align:left">f997 = 63895</td>
</tr>
<tr>
<td style="text-align:left">Destination Port</td>
<td style="text-align:left">目的端口</td>
<td style="text-align:left">0050 = 80</td>
</tr>
<tr>
<td style="text-align:left">Sequence Number</td>
<td style="text-align:left">序列号Seq</td>
<td style="text-align:left">6046 44fe - tcpdump显示的是相对序列号，即针对之前三次握手的序列号为基础</td>
</tr>
<tr>
<td style="text-align:left">Acknowledgment Number</td>
<td style="text-align:left">确认号Ack</td>
<td style="text-align:left">ae85 07c8</td>
</tr>
<tr>
<td style="text-align:left">Data Offset</td>
<td style="text-align:left">TCP头长度（单位4字节）</td>
<td style="text-align:left">8 即共8x4=32字节</td>
</tr>
</tbody>
</table>
<p>PS：TCP头之后就是DATA，即<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">GET / HTTP/1.1</span><br><span class="line">Host: www.v-ju.com.cn</span><br><span class="line">User-Agent: curl/7.51.0</span><br><span class="line">Accept: */*</span><br></pre></td></tr></table></figure></p>
<h4 id="UDP头"><a href="#UDP头" class="headerlink" title="UDP头"></a><font color="#55A8E7">UDP头</font></h4><p>tcpdump -i eth0 port 6050 -xx</p>
<pre>
16:33:20.761382 IP 192.168.0.88.24625 > 120.24.89.194.6050: UDP, length 2
  0x0000:  <font color="#E97D00">8cab 8ede 1301 54f6 c500 54fe 0800</font> <font color="#03AF59">4500
  0x0010:  001e 0000 4000 4011 a7f4 c0a8 0058 7818
  0x0020:  59c2</font> <font color="#55A8E7">6031 17a2 000a e821</font> 0d0a
</pre>

<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"> 0      7 8     15 16    23 24    31  </span><br><span class="line">+--------+--------+--------+--------+ </span><br><span class="line">|     Source      |   Destination   | </span><br><span class="line">|      Port       |      Port       | </span><br><span class="line">+--------+--------+--------+--------+ </span><br><span class="line">|                 |                 | </span><br><span class="line">|     Length      |    Checksum     | </span><br><span class="line">+--------+--------+--------+--------+</span><br></pre></td></tr></table></figure>
<table>
<thead>
<tr>
<th style="text-align:left">字段</th>
<th style="text-align:left">说明</th>
<th style="text-align:left">实际值</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left">Source Port</td>
<td style="text-align:left">原端口</td>
<td style="text-align:left">6031 = 24625</td>
</tr>
<tr>
<td style="text-align:left">Destination Port</td>
<td style="text-align:left">目的端口</td>
<td style="text-align:left">17a2 = 6050</td>
</tr>
<tr>
<td style="text-align:left">Length</td>
<td style="text-align:left">长度包含头部+数据</td>
<td style="text-align:left">000a = 10 = 8（UDP头）+ 2(数据)</td>
</tr>
</tbody>
</table>
<p>PS: UDP头之后就是DATA，即\r\n</p>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://smallmuou.gitee.io/blog/blog/2017/09/01/2017-09-01-像操作本地文件一样操作七牛云/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="smallmuou">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/blog/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="smallmuou's blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/blog/2017/09/01/2017-09-01-像操作本地文件一样操作七牛云/" itemprop="url">像操作本地文件一样操作七牛云</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-09-01T00:00:00+08:00">
                2017-09-01
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/blog/categories/工具/" itemprop="url" rel="index">
                    <span itemprop="name">工具</span>
                  </a>
                </span>

                
                
              
            </span>
          

          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>一提到文件操作，自然就想到了相关命令，ls、mkdir、rm、cp、mv等，而且作为linux入门用户，都能熟练地使用，那么七牛云是否也可以采用类似操作。本文我为大家介绍一款工具包，当然也是我自己本人的作品<a href="https://github.com/smallmuou/qn-ctl" target="_blank" rel="noopener">qn-ctl</a>.</p>
<p><asciinema-player src="http://ovjgvf1tp.bkt.clouddn.com/qn-ctl.json" autoplay preload="" loop></asciinema-player></p>
<p>qn-ctl是基于七牛官网提供的qrsctl进行再封装，抽象出ls、mkdir、rm、cp、mv等操作，只要能够操作linux的相关命令就能操作七牛云。</p>
<h2 id="安装"><a href="#安装" class="headerlink" title="安装"></a>安装</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">wget http://.../qrsctl-xxx <span class="comment"># 从https://developer.qiniu.com/kodo/tools/1300/qrsctl下载系统对应的二进制文件</span></span><br><span class="line">mv qrsctl-xxx qrsctl</span><br><span class="line">chmod +x qrsctl</span><br><span class="line">sudo mv qrsctl /usr/<span class="built_in">local</span>/bin</span><br><span class="line"></span><br><span class="line">git <span class="built_in">clone</span> https://github.com/smallmuou/qn-ctl</span><br><span class="line"><span class="built_in">cd</span> qn-cli</span><br><span class="line">sudo /bin/bash install.sh</span><br></pre></td></tr></table></figure>
<h4 id="使用"><a href="#使用" class="headerlink" title="使用"></a>使用</h4><ol>
<li>配置ak和sk</li>
<li>文件操作</li>
</ol>
<h4 id="例子"><a href="#例子" class="headerlink" title="例子"></a>例子</h4><ul>
<li>配置账号</li>
</ul>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">qn config your-ak your-sk</span><br></pre></td></tr></table></figure>
<ul>
<li>获取所有文件夹bucket</li>
</ul>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">qn ls</span><br></pre></td></tr></table></figure>
<ul>
<li>删除文件夹下所有文件</li>
</ul>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">qn rm <span class="built_in">test</span>/*</span><br></pre></td></tr></table></figure>
<ul>
<li>查看文件夹/文件详情</li>
</ul>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">qn <span class="built_in">stat</span> <span class="built_in">test</span></span><br></pre></td></tr></table></figure>
<ul>
<li>下载文件</li>
</ul>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">qn get <span class="built_in">test</span>/1 .</span><br></pre></td></tr></table></figure>
<ul>
<li>上传文件</li>
</ul>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">qn put hello <span class="built_in">test</span></span><br></pre></td></tr></table></figure>
<p>PS: 不允许上传空文件</p>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://smallmuou.gitee.io/blog/blog/2017/08/31/2017-08-31-记录并展现命令行/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="smallmuou">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/blog/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="smallmuou's blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/blog/2017/08/31/2017-08-31-记录并展现命令行/" itemprop="url">记录并展现命令行</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-08-31T00:00:00+08:00">
                2017-08-31
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/blog/categories/工具/" itemprop="url" rel="index">
                    <span itemprop="name">工具</span>
                  </a>
                </span>

                
                
              
            </span>
          

          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p><asciinema-player src="http://ovjgvf1tp.bkt.clouddn.com/summary.json" autoplay preload="" loop></asciinema-player></p>
<p>很多时候，为了更好的展示作品或解答问题，需要录制一段脚本，以前的做法是下一个gif录制软件，然后新建，选择区域，录制，时间控制，显得非常复杂，而且很容易出错；现在发现有一款软件<a href="https://asciinema.org/" target="_blank" rel="noopener">asciinema</a>可以录制并分享你的终端命令，非常棒的idea，现在将这个运用在我博客上，非常炫酷。下面记录下具体接入过程：</p>
<h4 id="1-下载asciinema-player-js和asciinema-player-css到相应的目录"><a href="#1-下载asciinema-player-js和asciinema-player-css到相应的目录" class="headerlink" title="1. 下载asciinema-player.js和asciinema-player.css到相应的目录"></a>1. 下载asciinema-player.js和asciinema-player.css到相应的目录</h4><h4 id="2-添加到html的head中"><a href="#2-添加到html的head中" class="headerlink" title="2. 添加到html的head中"></a>2. 添加到html的head中</h4><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">link</span> <span class="attr">rel</span>=<span class="string">"stylesheet"</span> <span class="attr">type</span>=<span class="string">"text/css"</span> <span class="attr">href</span>=<span class="string">"./asciinema-player.css"</span> /&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">script</span> <span class="attr">type</span>=<span class="string">"text/javascript"</span> <span class="attr">src</span>=<span class="string">"./asciinema-player.js"</span>&gt;</span><span class="undefined"></span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br></pre></td></tr></table></figure>
<h4 id="3-录制"><a href="#3-录制" class="headerlink" title="3. 录制"></a>3. 录制</h4><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">asciinema rec test.json</span><br></pre></td></tr></table></figure>
<p>PS: 按ctrl+D结束录制</p>
<h4 id="4-上传json至云端"><a href="#4-上传json至云端" class="headerlink" title="4. 上传json至云端"></a>4. 上传json至云端</h4><p>可以将json文件放于七牛或其它http服务器中</p>
<h4 id="5-展现"><a href="#5-展现" class="headerlink" title="5. 展现"></a>5. 展现</h4><p>在markdown文件或html中加入下面这段代码，即可实现本例开头的效果</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">asciinema-player</span> <span class="attr">src</span>=<span class="string">"http://ovjgvf1tp.bkt.clouddn.com/summary.json"</span> <span class="attr">autoplay</span> <span class="attr">preload</span> <span class="attr">loop</span>&gt;</span><span class="tag">&lt;/<span class="name">asciinema-player</span>&gt;</span></span><br></pre></td></tr></table></figure>
<p>PS: asciinema-player还有其他功能，可以查考官网文档</p>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
  </section>

  
  <nav class="pagination">
    <a class="extend prev" rel="prev" href="/blog/page/5/"><i class="fa fa-angle-left"></i></a><a class="page-number" href="/blog/">1</a><span class="space">&hellip;</span><a class="page-number" href="/blog/page/5/">5</a><span class="page-number current">6</span><a class="page-number" href="/blog/page/7/">7</a><span class="space">&hellip;</span><a class="page-number" href="/blog/page/20/">20</a><a class="extend next" rel="next" href="/blog/page/7/"><i class="fa fa-angle-right"></i></a>
  </nav>



          </div>
          


          

        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      

      <section class="site-overview-wrap sidebar-panel sidebar-panel-active">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <p class="site-author-name" itemprop="name">smallmuou</p>
              <p class="site-description motion-element" itemprop="description"></p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/blog/archives/">
              
                  <span class="site-state-item-count">197</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/blog/categories/index.html">
                  <span class="site-state-item-count">12</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            

          </nav>

          

          
            <div class="links-of-author motion-element">
                
                  <span class="links-of-author-item">
                    <a href="https://github.com/smallmuou" target="_blank" title="GitHub">
                      
                        <i class="fa fa-fw fa-globe"></i>GitHub</a>
                  </span>
                
            </div>
          

          
          

          
          

          

        </div>
      </section>

      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">smallmuou</span>

  
</div>

    <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>

    <span id="busuanzi_container_site_pv">总访问量<span id="busuanzi_value_site_pv"></span>次</span>
    <span class="post-meta-divider">|</span>



  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Muse</a> v5.1.4</div>




        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/blog/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/blog/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/blog/js/src/motion.js?v=5.1.4"></script>



  
  

  

  


  <script type="text/javascript" src="/blog/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  





  

  

  

  
  

  

  

  

</body>
</html>
